use std::marker::Copy;
use std::cmp::PartialOrd;

pub fn bubble_sort(arr : &mut [i32]) {
    for i in 0..arr.len(){
        for j in 0..arr.len() - 1 - i {
            if arr[j] > arr[j+1]{
                arr.swap(j, j + 1);
            }
        }
    }
}

pub fn bubble_sort_optimized<T: Copy + PartialOrd>(arr : &mut[T]) {
    for i in 0..arr.len(){
        for j in 0..arr.len() - 1 - i {
            if arr[j] > arr[j+1]{
                arr.swap(j, j + 1);
            }
        }
    }
}

fn main(){
    println!("Base Bubble Sort Demo");
    let mut number = vec![22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70];
    println!("{:?}", number);
    bubble_sort(&mut number);
    println!("{:?}", number);

    println!("Optimized Number Bubble Sort Demo");
    let mut opt_number = vec![22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70];
    println!("{:?}", opt_number);
    bubble_sort_optimized(&mut opt_number);
    println!("{:?}", opt_number);

    println!("Optimized String Bubble Sort Demo");
    let mut arr = vec!['x', 'a', 'b', 'x', 'p'];
    println!("{:?}", arr);
    bubble_sort_optimized(&mut arr);
    println!("{:?}", arr);
}